$(function(){
	$('.countdown').each(function(index,obj){
		var str = $(obj).attr('data');
		obj.arr = null;
			obj.arr = getTime(str,1);
			$(obj).children('.hour').html(obj.arr.hour);
			$(obj).children('.minute').html(obj.arr.minute);
			$(obj).children('.seconds').html(obj.arr.seconds);
		setInterval(function(){
			obj.arr = getTime(str,1);
			$(obj).children('.hour').html(obj.arr.hour);
			$(obj).children('.minute').html(obj.arr.minute);
			$(obj).children('.seconds').html(obj.arr.seconds);
		},1000)
	})


	//倒计时
	function getTime(str,type){
			array = {};
		    var data = new Date();
			var time = data.getTime();
			switch(type){
				case 1:
					str = str.replace(/-/g,'/');
					var newData =new Date(Date.parse(str));
					var newTime = newData.getTime();
					var  num = newTime-time;
					if(num>0){
					var day = toZero(parseInt(num/(3600*24*1000)))
					num =num%(3600*24*1000);
					var hour = toZero(parseInt(num/(3600*1000)));
					num = num%(3600*1000);
					var minute = toZero(parseInt(num/(60*1000)));
					num = num%(60*1000);
					var seconds = toZero(parseInt(num/1000));
					}else{
						day = hour = minute =seconds = 0;
					}
				break;
				case 2:
			    	var  num = parseInt(str)-parseInt(time/1000);
			    	if(num>0){
					var day = toZero(parseInt(num/(3600*24)))
					num =num%(3600*24);
					var hour = toZero(parseInt(num/(3600)));
					num = num%(3600);
					var minute = toZero(parseInt(num/(60)));
					num = num%(60);
					var seconds = toZero(parseInt(num));
					}else{
						day = hour = minute =seconds = 0;
					}
					break;
				}
				array = {'day':day,'hour':hour,'minute':minute,'seconds':seconds}
				return array;
   }
   				function toZero(num){
   					if(num<10){
   						num ='0'+num
   					}
   					return num;
   				}



})
